# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: t3ddy  <t3ddy1988 "at" gmail {dot} com>
# Contributor: Adrián Chaves Fernández (Gallaecio) <adriyetichaves@gmail.com>
pkgname=0ad
pkgver=a26
_pkgver=0.0.26-alpha
pkgrel=6
pkgdesc="Cross-platform, 3D and historically-based real-time strategy game"
arch=('loong64' 'x86_64')
url="http://play0ad.com/"
license=('GPL2' 'CCPL')
depends=('0ad-data' 'binutils' 'boost-libs' 'curl' 'enet' 'libogg' 'libpng' 'libvorbis'
         'libxml2' 'openal' 'sdl2' 'wxwidgets-gtk3' 'zlib' 'libgl' 'glu' 'fmt'
         'gloox' 'miniupnpc' 'libminiupnpc.so' 'icu' 'nspr' 'libsodium' 'which')
makedepends=('boost' 'cmake' 'mesa' 'zip' 'libsm' 'rust' 'python' 'clang')
options=('!lto') # breaks spidermonkey linking (https://bugs.gentoo.org/746947)
source=("https://releases.wildfiregames.com/$pkgname-$_pkgver-unix-build.tar.xz"
    0ad-fix-build.patch
    0ad-la64.patch)
sha512sums=('aaf647d5d8454c244015d2a198beeaaebc571a5bc96446f3acff8dbd05f9843029c500bf4162651a5e1fcdb42bd5fb5b4f5c512c78372479fbd8565dd093f272'
            '956effc37bbad8ca44a5e82a8750ca82c1c2347152dd684ebc2921953d4fa81ef9291b5bb5de05559b2b4ef79c336b837216892f0bcf806e50aac8c4ea42edde'
            'c01e52a4241736eda82f6002c3627d9c4b5b505109969fc608d95dd71db8681df8f3de6a372bca8fe977bee14f5180f4c27681e40d26b0a06ddc556122886d04')

prepare() {
  cd "$pkgname-$_pkgver"
  patch -d libraries/source/spidermonkey -p1 -i $srcdir/0ad-fix-build.patch

  cp $srcdir/0ad-la64.patch libraries/source/spidermonkey/0ad-la64.patch
  echo "patch -p5 < ../0ad-la64.patch" >> libraries/source/spidermonkey/patch.sh

  echo "cp /usr/share/automake-1.16/config.* build/autoconf/" >> libraries/source/spidermonkey/patch.sh
}

build() {
  cd "$pkgname-$_pkgver/build/workspaces"

  ./update-workspaces.sh -j$(nproc) \
      --without-pch \
      --bindir=/usr/bin \
      --libdir=/usr/lib/0ad \
      --datadir=/usr/share/0ad/data

  cd gcc

  VERBOSE=1 make
}

package() {
  cd "$pkgname-$_pkgver"
  install -d "${pkgdir}"/usr/{bin,lib/0ad,share/"${pkgname}"/data}
  install -Dm755 binaries/system/pyrogenesis "${pkgdir}/usr/bin"
  install -Dm755 binaries/system/*.so "${pkgdir}/usr/lib/0ad"

  cp -r binaries/data/l10n/ "${pkgdir}/usr/share/${pkgname}/data/"

  install -Dm755 build/resources/${pkgname}.sh "${pkgdir}/usr/bin/${pkgname}"
  install -Dm644 build/resources/${pkgname}.desktop "${pkgdir}/usr/share/applications/${pkgname}.desktop"
  install -Dm644 build/resources/${pkgname}.png "${pkgdir}/usr/share/pixmaps/${pkgname}.png"
}
